<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML>
<html>
<head>
<c:set var="title" value="添加地址" scope="request" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link href="shop/css/shop-top.css" rel="stylesheet" />
<link href="shop/css/shop-detail.css" rel="stylesheet" />
<link href="shop/css/shop-footer.css" rel="stylesheet" />
<link href="shop/css/shop-tuan.css" rel="stylesheet" />
<link href="shop/css/shop-common.css" rel="stylesheet" />
<link href="shop/css/shop-select2.css" rel="stylesheet" />

<jsp:include page="/head.jsp" />
<script type="text/javascript" src="shop/js/shop-/public.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="shop/js/shop-layer.js"></script>
<script type="text/javascript" src="shop/js/shop-area.js"></script>
<script type="text/javascript" src="shop/js/shop-location.js"></script>
<script type="text/javascript" src="shop/js/shop-select2.js"></script>
<script type="text/javascript" src="shop/js/shop-select2_locale_zh-CN.js"></script>

</head>

<body>
    <c:import url="/news-class.do?mb=header" />
	<%@ include file="jsps/top.jsp"%>
	<div class="yershop_wrapper">
		<%@ include file="jsps/hader.jsp"%>
		<div class="menu-wrapper">
			<div class="nava">
				<div class="nav-all">
				</div>
				<ul class="menu">
					<li><a href="shop.html" target="_self">首页</a></li>
					<li><a href="shop.html" target="_blank">团购</a></li>
					<li><a href="shop.html" target="_self">抢购</a></li>
					<li><a href="shop.html" target="_self">预约</a></li>
				</ul>
			</div>
		</div>
		<!-- /菜单 -->

		<!-- 主体 -->
		<div class="commom_wrapper">

			<div class="main">
				<div class="main_center">
					<div class="center_left">
						<!-- 左侧菜单 -->
						<h3>
							<a rel="nofollow" href="javascript:vod(0)" class="home-me">我的会员中心</a>
						</h3>
						<dl>
							<dd>
								<%-- <a rel="nofollow" href="userMain.page"
									<c:if test="${rightPage=='orderAll' || rightPage=='orderDetail' }">class="current"</c:if>>我的订单</a> --%>
								<!-- <a rel="nofollow"  href="order.jsp" <c:import url="order.do"></c:import>>我的订单</a> -->
								<a rel="nofollow" href="sss-1.do">我的订单</a>
							</dd>
						</dl>

						<dl class="last">
							<dd>
								<%-- <a rel="nofollow" href="userAddress.page"
									<c:if test="${rightPage=='address' || rightPage=='addAddress' }">class="current"</c:if>>地址管理</a> --%>
									<a rel="nofollow"  href="userAddress.page"  class="current">地址管理</a>
							</dd>
							<dd>
								<a rel="nofollow" href="index.cart">我的购物车</a>
							</dd>
						</dl>

						<script>
							/* 左边菜单高亮 */
							url = window.location.pathname
									+ window.location.search;
							url = url
									.replace(
											/(\/(p)\/\d+)|(&p=\d+)|(\/(id)\/\d+)|(&id=\d+)|(\/(group)\/\d+)|(&group=\d+)/,
											"");

							$("a[href='" + url + "']").addClass("current");
						</script>

						<!-- 左侧菜单 -->

					</div>

					<%-- <%@include file="jsps/userMain/addAddress.jsp"%> --%>

					<!-- 添加地址 -->
					<div class="center_right" style="display: block;">
						<div class="red"
							style="clear: both; overflow: hidden; padding: 10px;">收货地址管理（选中表示为默认）</div>
						<form method="post" class="person-add" name="form">
							<div class="form-item">
								<select id="loc_province" style="width: 120px;"></select>
								<select id="loc_city" style="width: 120px; margin-left: 10px"></select>
								<select id="loc_town" style="width: 120px; margin-left: 10px"></select>
							</div>
							<div class="form-item">
								详细地址:<input id="address" name="address" type="text">
							</div>
							<div class="form-item">
								联系人：<input name="realname" id="realname" type="text">
							</div>
							<div class="form-item">
								手机号：<input id="phone" name="cellphone" type="text">
							</div>
							<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="isdefault"
								checked="checked" name="default" type="checkbox">设为默认收货地址
							<!-- <div class="form-item">
							    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<input class=" btn-xiugai redd" id="btn-save" value="保存" type="button" onclick="baocun();return false;">
								<a class=" btn-xiugai redd" id="btn-save" type="button" onclick="baocun();return false;">保存</a>
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<a href="userAddress.page" class=" btn-xiugai redd">返回</a>
							</div> -->
							<div class="form-item">
								<input class=" btn-xiugai redd" id="btn-save" value="保存" type="button" onclick="baocun();return false;">
								<a href="userAddress.page" class=" btn-xiugai blue">返回</a>
							</div>
						</form>
						<script type="text/javascript">

						/* $('#btn-save').click(
								function() {
									var province = $('#loc_province').select2('data').text; //省
									var city = $('#loc_city').select2('data').text; //市
									var area = $('#loc_town').select2('data').text; //县
									var posi = $('#address').val();
									var pho = $('#phone').val();
									var rel = $('#realname').val();
									var msg = 0;

									if (province == '省份' || city == '地级市' 	|| area == '市、县、区') {
										layer.alert("地址请填写完整", {
											icon : 0
										});
									} 
									else if (window.confirm('你确定要添加地址吗？')) {
										if ($("#isdefault").is(':checked')) {
											msg = 1;
										}
										$.ajax({
													type : "post", //传送的方式,get/post
													url : "add.address", //发送数据的地址
													data : {
														province : province,
														city : city,
														area : area,
														posi : posi,
														pho : pho,
														rel : rel,
														msg : msg
													},
													dataType : "json",
													success : function(data) {
														if (data.success) {
															layer.alert(
																			"添加成功！",
																			{
																				icon : 1
																			},
																			function(index) {
																				//do something
																				layer.close(index);
																				location.href = 'userAddress.page';
																			});
														} else {
															layer.alert(
																			"添加失败！",
																			{
																				icon : 2
																			});
														}
													},
													error : function(event,XMLHttpRequest,ajaxOptions,thrownError) {
														alert(XMLHttpRequest + thrownError);
													}
												});
									}
									//alert(province+city+area);
								}); */
						
							function baocun() {
								var province = $('#loc_province').select2(
										'data').text; //省
								var city = $('#loc_city').select2('data').text; //市
								var area = $('#loc_town').select2('data').text; //县
								var posi = $('#address').val();
								var pho = $('#phone').val();
								var rel = $('#realname').val();
								var msg = 0;

								if (province == '省份' || city == '地级市'
										|| area == '市、县、区') {
									layer.alert("地址请填写完整", {
										icon : 0
									});
								} else if (window.confirm('你确定要添加地址吗？')) {
									if ($("#isdefault").is(':checked')) {
										msg = 1;
									}
									$
											.ajax({
												type : "post", //传送的方式,get/post
												url : "add.address", //发送数据的地址
												data : {
													province : province,
													city : city,
													area : area,
													posi : posi,
													pho : pho,
													rel : rel,
													msg : msg
												},
												dataType : "json",
												success : function(data) {
													if (data.success) {
														layer
																.alert(
																		"添加成功！",
																		{
																			icon : 1
																		},
																		function(
																				index) {
																			//do something
																			layer
																					.close(index);
																			location.href = 'userAddress.page';
																		});
													} else {
														layer.alert("添加失败！", {
															icon : 2
														});
													}
												},
											/* error : function(event,XMLHttpRequest,ajaxOptions,thrownError) {
												alert(XMLHttpRequest + thrownError);
											} */
											});
								}
							}
						</script>
					</div>

				</div>
			</div>
			<!-- 主体 -->

			<!-- 购物车js -->
			<script>
				//购物车显示与隐藏
				var Shopcart = document.getElementById('shopping_cart');
				var Goodsmenu = document.getElementById('goods');
				var timerr = null;//定义定时器变量
				//鼠标移入div1或div2都把定时器关闭了，不让他消失
				Shopcart.onmouseover = Goodsmenu.onmouseover = function() {
					Goodsmenu.style.display = 'block';
					clearTimeout(timerr);
				}
				//鼠标移出div1或div2都重新开定时器，让他延时消失
				Shopcart.onmouseout = Goodsmenu.onmouseout = function() {
					//开定时器
					timerr = setTimeout(function() {
						Goodsmenu.style.display = 'none';
					}, 10);
				}

				//购物车动态删除
				function delcommon(event) { //获取事件源
					event = event ? event : window.event;
					var obj = event.srcElement ? event.srcElement
							: event.target;
					//这时obj就是触发事件的对象，可以使用它的各个属性 
					//还可以将obj转换成jquery对象，方便选用其他元素 
					str = obj.innerHTML.replace(/<\/?[^>]*>/g, ''); //去除HTML tag

					var $obj = $(obj);
					var str = $obj.parent().prev().html();
					if (obj.rel == "del") {
						var str = obj.name;
						var uexist = "";
						//全选的实现 定义删的发送路径
						if (uexist) {
							var del = '/index.php?s=/Home/Shopcart/delItemByuid.html';
						} else {
							var del = 'delShoppingCart.goods';

						}

						$
								.ajax({
									type : 'post', //传送的方式,get/post
									url : del, //发送数据的地址
									data : {
										sort : str
									},
									dataType : "json",
									success : function(data) {
										var $obj = $(obj);
										$obj.parents("li").remove();
										if (data.sum == "0") { //判断购物车数量是否为0，为0则隐藏底部查看工具
											$("div.sc_goods_foot").hide();
											var html = '<p class="sc_goods_none" >您的购物车还是空的，赶紧行动吧！</p>';
											$("ul.sc_goods_ul").html(html);

										} else {
											$("div.sc_goods_foot").show();
										}

									},
									error : function(event, XMLHttpRequest,
											ajaxOptions, thrownError) {
										alert(XMLHttpRequest + thrownError);
									}
								})
					}

				}
				//购物车删除结束
			</script>
			<!-- /购物车js -->

			<!-- 底部 -->

			<!-- 底部-->
			<script type="text/javascript" charset="utf-8"
				src="shop/js/shop-menudown.js"></script>

		</div>
	</div>
	<%@ include file="jsps/footer.jsp"%>
</body>
</html>